public class 合并两个有序链表 {
    
    public static void main(String[] args) {
        


    }

    public static ListNode mergeTwoLists(ListNode list1, ListNode list2) {

        if(null == list1 || null == list2){

            return null==list1 ? list2 : list1;
        }

        ListNode root = new ListNode(-1);

        ListNode pre = root;

        while (list1!=null && list2!=null) {
            

            if(list1.val < list2.val){

                pre.next = list1;
                list1 = list1.next;
            } else{

                pre.next = list2;
                list2 = list2.next;
            }

            pre = pre.next;
        }

        pre.next = list1==null?list2:list1;

        return root.next;
        
    }

    public static class ListNode{

        int val;
        ListNode next;

        public ListNode(int val){

            this.val = val;
        }
    }
}
